//
//  UIView+THAddForRoundedCorner.m
//  MengLiao
//
//  Created by xiuxin on 2022/7/15.
//  Copyright © 2022 BaseBusiness. All rights reserved.
//

#import "UIView+THAddForRoundedCorner.h"

@implementation CALayer (THAddForRoundedCorner)

- (void)zh_roundedCornerWithRadius:(CGFloat)radius {
    self.cornerRadius = radius;
    self.masksToBounds = YES;
}

- (void)zh_roundedCornerWithRadius:(CGFloat)radius
                       borderColor:(UIColor *)borderColor
                       borderWidth:(CGFloat)borderWidth{
    self.masksToBounds = YES;
    self.cornerRadius = radius;
    self.borderColor = borderColor.CGColor;
    self.borderWidth = borderWidth;
}

- (void)zh_roundedCornerWithRadius:(CGFloat)radius corners:(UIRectCorner)corners{
    UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
    CAShapeLayer* shape = [[CAShapeLayer alloc] init];
    [shape setPath:rounded.CGPath];
    self.mask = shape;
}

- (void)zh_roundedCornerWithCornerRadii:(CGSize)cornerRadii corners:(UIRectCorner)corners borderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth{
    UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:cornerRadii];
    CAShapeLayer* shape = [[CAShapeLayer alloc] init];
    [shape setPath:rounded.CGPath];
    self.mask = shape;
    self.masksToBounds = YES;
    self.borderColor = borderColor.CGColor;
    self.borderWidth = borderWidth;
}
@end

@implementation UIView (THAddForRoundedCorner)

- (void)zh_roundedCornerWithRadius:(CGFloat)radius {
    self.layer.cornerRadius = radius;
    self.layer.masksToBounds = YES;
}

- (void)zh_roundedCornerWithRadius:(CGFloat)radius
                       borderColor:(UIColor *)borderColor
                       borderWidth:(CGFloat)borderWidth{
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = radius;
    self.layer.borderColor = borderColor.CGColor;
    self.layer.borderWidth = borderWidth;
}

- (void)zh_roundedCornerWithRadius:(CGFloat)radius corners:(UIRectCorner)corners{
    UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
    CAShapeLayer* shape = [[CAShapeLayer alloc] init];
    [shape setPath:rounded.CGPath];
    self.layer.mask = shape;
}

- (void)zh_roundedCornerWithCornerRadii:(CGSize)cornerRadii corners:(UIRectCorner)corners borderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth{
    UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:cornerRadii];
    CAShapeLayer* shape = [[CAShapeLayer alloc] init];
    [shape setPath:rounded.CGPath];
    self.layer.mask = shape;
    self.layer.masksToBounds = YES;
    self.layer.borderColor = borderColor.CGColor;
    self.layer.borderWidth = borderWidth;
}

@end
